DIR_BUILD = ../build
DIR_BUILD_HEMU = $(DIR_BUILD)/HEMU
DIR_SRC_HEMU = ./src
DIR_INCLUDE_HEMU = ./include


SRC_HEMU = $(wildcard $(DIR_SRC_HEMU)/*.cpp)
INC_HEMU = $(wildcard $(DIR_INCLUDE_HEMU)/*.h)
OBJ_HEMU = $(patsubst %.cpp, %.o, $(foreach file, $(SRC_HEMU), $(DIR_BUILD_HEMU)/$(notdir $(file))))
# `patsubst` is a function that substitutes the first pattern with the second pattern in a list of words
#EXE_HEMU = $(DIR_BUILD)/hemu
EXE_HEMU = $(DIR_BUILD)/interpreter

CXX = g++
CXXFLAGS = -Wall -O2 -I$(DIR_INCLUDE_HEMU)

hemu: $(EXE_HEMU)

$(DIR_BUILD_HEMU)/%.o : $(DIR_SRC_HEMU)/%.cpp $(INC_HEMU)
	mkdir -p $(DIR_BUILD_HEMU)
	$(CXX) $(CXXFLAGS) -c $< -o $@
# `$<` is the first prerequisite

$(EXE_HEMU): $(OBJ_HEMU)
	$(CXX) $^ -o $@
# `$^` is all prerequisites

clean:
	rm $(OBJ_HEMU)
